# -*- coding: utf-8 -*-  
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )

import requests
from lxml import etree
import json

def spider(url):
	html=requests.get(url)
	select =etree.HTML(html.text)
	content_filed=select.xpath('//div[@class="l_post j_l_post l_post_bright  "]')
	item={}
	for each in content_filed:
		reply_info=json.loads(each.xpath('@data-field')[0])
		author=reply_info['author']['user_name']
		reply_time=reply_info['content']['date']
		content=each.xpath('div[@class="d_post_content_main"]/div/cc/div[@class="d_post_content j_d_post_content  clearfix"]/text()')
		item['user_name']=author
		item['time']=reply_time
		item['content']=content
		print author,reply_time,content[0]

for i in range(1,20)
	url="http://tieba.baidu.com/p/5088137503?pn={}".format(i)
	spider(url)
